package com.studymaster.util;

import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TimeUtil {

	public static class SimpleDate{
		public int year		=2000;
		public int month	=1;
		public int day		=1;
		
		public SimpleDate(String s){
			Pattern pattern = Pattern.compile("\\d{4}-\\d{2}-\\d{2}");
			Matcher matcher = pattern.matcher(s);
			if ( matcher.find() ){
				year  = Integer.valueOf(s.substring(0, s.indexOf("-")));
				month = Integer.valueOf(s.substring(s.indexOf("-")+1, s.indexOf("-")+3));
				day   = Integer.valueOf(s.substring(s.lastIndexOf("-")+1));
			}
			
		}
	}
	
	public static String convertIntToStringTime(int time){
		String sMin = "";
		int min = time%100;
		sMin = min+"";
		if ( min / 10 == 0 ){
			sMin = "0"+min;
		}
		return (time/100)+":"+sMin;
	}
	
	public static String getDateByDay(int day){
		Calendar calendar = Calendar.getInstance();
		Date today = calendar.getTime();
		
		int dayOfWeek = today.getDay();
		if( dayOfWeek == 0 ){
			dayOfWeek = 7;
		}
		
		today.setDate(today.getDate()+day-dayOfWeek);
		
		String date = ""+(today.getYear()+1900)
						+"-"
						+(today.getMonth()+1)
						+"-"
						+(today.getDate());
		
		return date;
	}
}
